package com.starlink.client.jd.request;

import com.lop.open.api.sdk.domain.ECAP.CommonCreateOrderApi.commonCheckPreCreateOrderV1.CommonCreateOrderRequest;
import com.starlink.client.jd.request.base.CommonProductInfo;
import com.starlink.client.jd.request.base.Contact;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 下单前置校验入参模型
 * 传参规则详情见京东文档
 * <a href="https://open.jdl.com/#/open-business-document/api-doc/267/842"/>
 */
@Data
@NoArgsConstructor
public class PreCheckRequest implements Serializable {
    private static final long serialVersionUID = -4624467070581097708L;
    /**
     * 寄件人信息
     */
    private Contact senderContact;
    /**
     * 收件人信息
     */
    private Contact receiverContact;
    /**
     * 下单来源 0-c2c 1-b2c 2-c2b 4-kyb2c 5- kyc2c，
     * 详细说明：https://cloud.jdl.com/#/open-business-document/access-guide/267/54152
     */
    private Integer orderOrigin;
    /**
     * 客户编码；orderOrigin为 1或者 2 时必填；与京东物流签约后生成，长度1-32
     */
    private String customerCode;
    /**
     * 产品信息
     */
    private CommonProductInfo productsReq;

    /**
     * 业务模型转换
     *
     * @return
     */
    public CommonCreateOrderRequest toCommonCreateOrderRequest() {
        CommonCreateOrderRequest requestDTO = new CommonCreateOrderRequest();
        requestDTO.setOrderOrigin(this.orderOrigin);
        requestDTO.setCustomerCode(this.customerCode);
        requestDTO.setProductsReq(this.productsReq.toJd4PreCreate());
        requestDTO.setReceiverContact(this.receiverContact.toJdPreCreate());
        requestDTO.setSenderContact(this.senderContact.toJdPreCreate());
        return requestDTO;
    }
}
